Skip to content

[llvm] annotate interfaces in llvm/CGData and llvm/CodeGen for DLL export #140823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025

Conversation

andrurogerz
Copy link
Contributor

Purpose

This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the llvm/CGData and llvm/CodeGen libraries. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build.

Background

This effort is tracked in #109483. Additional context is provided in this discourse, and documentation for LLVM_ABI and related annotations is found in the LLVM repo here.

The bulk of these changes were generated automatically using the Interface Definition Scanner (IDS) tool, followed formatting with git clang-format.

The following manual adjustments were also applied after running IDS on Linux:

  • Add LLVM_ABI to a subset of private class methods and fields that require export
  • Add LLVM_TEMPLATE_ABI and LLVM_EXPORT_TEMPLATE to exported instantiated templates defined via X-macro
  • Add LLVM_ABI_FRIEND to friend member functions declared with LLVM_ABI
  • Explicitly make classes non-copyable where needed to due IDS adding LLVM_ABI at the class level
  • Add #include "llvm/Support/Compiler.h" to files where it was not auto-added by IDS due to no pre-existing block of include statements.
  • Add LLVM_ABI to a small number of symbols that require export but are not declared in headers

Validation

Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:

  • Windows with MSVC
  • Windows with Clang
  • Linux with GCC
  • Linux with Clang
  • Darwin with Clang

@andrurogerz andrurogerz marked this pull request as ready for review May 21, 2025 18:32
@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-llvm-globalisel
@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-llvm-regalloc

Author: Andrew Rogers (andrurogerz)

Changes

Purpose

This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the llvm/CGData and llvm/CodeGen libraries. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build.

Background

This effort is tracked in #109483. Additional context is provided in this discourse, and documentation for LLVM_ABI and related annotations is found in the LLVM repo here.

The bulk of these changes were generated automatically using the Interface Definition Scanner (IDS) tool, followed formatting with git clang-format.

The following manual adjustments were also applied after running IDS on Linux:

  • Add LLVM_ABI to a subset of private class methods and fields that require export
  • Add LLVM_TEMPLATE_ABI and LLVM_EXPORT_TEMPLATE to exported instantiated templates defined via X-macro
  • Add LLVM_ABI_FRIEND to friend member functions declared with LLVM_ABI
  • Explicitly make classes non-copyable where needed to due IDS adding LLVM_ABI at the class level
  • Add #include "llvm/Support/Compiler.h" to files where it was not auto-added by IDS due to no pre-existing block of include statements.
  • Add LLVM_ABI to a small number of symbols that require export but are not declared in headers

Validation

Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations:

  • Windows with MSVC
  • Windows with Clang
  • Linux with GCC
  • Linux with Clang
  • Darwin with Clang

Patch is 646.67 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/140823.diff

101 Files Affected:

  • (modified) llvm/include/llvm/CGData/CodeGenData.h (+17-16)
  • (modified) llvm/include/llvm/CGData/CodeGenDataReader.h (+6-5)
  • (modified) llvm/include/llvm/CGData/CodeGenDataWriter.h (+6-5)
  • (modified) llvm/include/llvm/CGData/OutlinedHashTree.h (+9-8)
  • (modified) llvm/include/llvm/CGData/OutlinedHashTreeRecord.h (+5-4)
  • (modified) llvm/include/llvm/CGData/StableFunctionMap.h (+7-6)
  • (modified) llvm/include/llvm/CGData/StableFunctionMapRecord.h (+7-5)
  • (modified) llvm/include/llvm/CodeGen/AccelTable.h (+24-18)
  • (modified) llvm/include/llvm/CodeGen/AsmPrinter.h (+3-2)
  • (modified) llvm/include/llvm/CodeGen/AsmPrinterHandler.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/CallingConvLower.h (+34-32)
  • (modified) llvm/include/llvm/CodeGen/CodeGenTargetMachineImpl.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/CommandFlags.h (+83-78)
  • (modified) llvm/include/llvm/CodeGen/DIE.h (+71-61)
  • (modified) llvm/include/llvm/CodeGen/DroppedVariableStatsMIR.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/GCMetadata.h (+3-2)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h (+25-21)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/CSEMIRBuilder.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h (+5-4)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h (+10-8)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/GISelChangeObserver.h (+12-8)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/GISelValueTracking.h (+7-5)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/InstructionSelect.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h (+9-8)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/Legalizer.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h (+187-161)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h (+56-47)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/LoadStoreOpt.h (+9-7)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/LostDebugLocObserver.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/GlobalISel/Utils.h (+192-176)
  • (modified) llvm/include/llvm/CodeGen/ISDOpcodes.h (+17-15)
  • (modified) llvm/include/llvm/CodeGen/LexicalScopes.h (+13-10)
  • (modified) llvm/include/llvm/CodeGen/LiveInterval.h (+60-56)
  • (modified) llvm/include/llvm/CodeGen/LiveIntervalCalc.h (+6-5)
  • (modified) llvm/include/llvm/CodeGen/LiveIntervals.h (+51-48)
  • (modified) llvm/include/llvm/CodeGen/LiveRangeCalc.h (+10-10)
  • (modified) llvm/include/llvm/CodeGen/LiveRegUnits.h (+7-6)
  • (modified) llvm/include/llvm/CodeGen/LiveVariables.h (+35-33)
  • (modified) llvm/include/llvm/CodeGen/LowLevelTypeUtils.h (+6-5)
  • (modified) llvm/include/llvm/CodeGen/MIRFormatter.h (+7-5)
  • (modified) llvm/include/llvm/CodeGen/MIRParser/MIRParser.h (+8-7)
  • (modified) llvm/include/llvm/CodeGen/MIRPrinter.h (+10-9)
  • (modified) llvm/include/llvm/CodeGen/MachineBasicBlock.h (+110-98)
  • (modified) llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h (+36-32)
  • (modified) llvm/include/llvm/CodeGen/MachineCycleAnalysis.h (+7-5)
  • (modified) llvm/include/llvm/CodeGen/MachineDomTreeUpdater.h (+6-5)
  • (modified) llvm/include/llvm/CodeGen/MachineDominators.h (+24-22)
  • (modified) llvm/include/llvm/CodeGen/MachineFrameInfo.h (+18-14)
  • (modified) llvm/include/llvm/CodeGen/MachineFunction.h (+8-8)
  • (modified) llvm/include/llvm/CodeGen/MachineFunctionAnalysis.h (+5-4)
  • (modified) llvm/include/llvm/CodeGen/MachineFunctionAnalysisManager.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/MachineFunctionPass.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/MachineInstr.h (+148-134)
  • (modified) llvm/include/llvm/CodeGen/MachineInstrBuilder.h (+27-24)
  • (modified) llvm/include/llvm/CodeGen/MachineInstrBundle.h (+13-10)
  • (modified) llvm/include/llvm/CodeGen/MachineJumpTableInfo.h (+17-13)
  • (modified) llvm/include/llvm/CodeGen/MachineLoopInfo.h (+20-16)
  • (modified) llvm/include/llvm/CodeGen/MachineMemOperand.h (+20-16)
  • (modified) llvm/include/llvm/CodeGen/MachineModuleInfo.h (+17-14)
  • (modified) llvm/include/llvm/CodeGen/MachineModuleSlotTracker.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/MachineOperand.h (+50-43)
  • (modified) llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h (+9-6)
  • (modified) llvm/include/llvm/CodeGen/MachinePassManager.h (+15-14)
  • (modified) llvm/include/llvm/CodeGen/MachinePostDominators.h (+24-19)
  • (modified) llvm/include/llvm/CodeGen/MachineRegisterInfo.h (+54-49)
  • (modified) llvm/include/llvm/CodeGen/MachineScheduler.h (+84-84)
  • (modified) llvm/include/llvm/CodeGen/MachineSizeOpts.h (+13-11)
  • (modified) llvm/include/llvm/CodeGen/MachineStableHash.h (+8-6)
  • (modified) llvm/include/llvm/CodeGen/MachineVerifier.h (+3-2)
  • (modified) llvm/include/llvm/CodeGen/MacroFusion.h (+5-4)
  • (modified) llvm/include/llvm/CodeGen/NonRelocatableStringpool.h (+4-3)
  • (modified) llvm/include/llvm/CodeGen/PBQPRAConstraint.h (+8-2)
  • (modified) llvm/include/llvm/CodeGen/Passes.h (+158-155)
  • (modified) llvm/include/llvm/CodeGen/PseudoSourceValue.h (+12-8)
  • (modified) llvm/include/llvm/CodeGen/PseudoSourceValueManager.h (+10-8)
  • (modified) llvm/include/llvm/CodeGen/RegisterBank.h (+8-6)
  • (modified) llvm/include/llvm/CodeGen/RegisterClassInfo.h (+5-4)
  • (modified) llvm/include/llvm/CodeGen/RegisterPressure.h (+85-81)
  • (modified) llvm/include/llvm/CodeGen/ReplaceWithVeclib.h (+3-2)
  • (modified) llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h (+24-22)
  • (modified) llvm/include/llvm/CodeGen/ScheduleDAG.h (+25-23)
  • (modified) llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/ScheduleDAGMutation.h (+3-1)
  • (modified) llvm/include/llvm/CodeGen/SchedulerRegistry.h (+18-17)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+709-615)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAGAddressAnalysis.h (+15-11)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+115-104)
  • (modified) llvm/include/llvm/CodeGen/SlotIndexes.h (+20-19)
  • (modified) llvm/include/llvm/CodeGen/StackMaps.h (+19-20)
  • (modified) llvm/include/llvm/CodeGen/TargetFrameLowering.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/TargetInstrInfo.h (+3-2)
  • (modified) llvm/include/llvm/CodeGen/TargetLowering.h (+18-14)
  • (modified) llvm/include/llvm/CodeGen/TargetPassConfig.h (+4-3)
  • (modified) llvm/include/llvm/CodeGen/TargetRegisterInfo.h (+12-8)
  • (modified) llvm/include/llvm/CodeGen/TargetSchedule.h (+28-25)
  • (modified) llvm/include/llvm/CodeGen/TargetSubtargetInfo.h (+2-1)
  • (modified) llvm/include/llvm/CodeGen/ValueTypes.h (+32-31)
  • (modified) llvm/include/llvm/CodeGen/VirtRegMap.h (+19-16)
  • (modified) llvm/unittests/CodeGen/RegAllocScoreTest.cpp (+6-5)
diff --git a/llvm/include/llvm/CGData/CodeGenData.h b/llvm/include/llvm/CGData/CodeGenData.h
index 0e7dd2f5b5c1a..ad7fa579f7508 100644
--- a/llvm/include/llvm/CGData/CodeGenData.h
+++ b/llvm/include/llvm/CGData/CodeGenData.h
@@ -23,6 +23,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Caching.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/TargetParser/Triple.h"
 #include <mutex>
@@ -34,9 +35,9 @@ enum CGDataSectKind {
 #include "llvm/CGData/CodeGenData.inc"
 };
 
-std::string getCodeGenDataSectionName(CGDataSectKind CGSK,
-                                      Triple::ObjectFormatType OF,
-                                      bool AddSegmentInfo = true);
+LLVM_ABI std::string getCodeGenDataSectionName(CGDataSectKind CGSK,
+                                               Triple::ObjectFormatType OF,
+                                               bool AddSegmentInfo = true);
 
 enum class CGDataKind {
   Unknown = 0x0,
@@ -47,7 +48,7 @@ enum class CGDataKind {
   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/StableFunctionMergingMap)
 };
 
-const std::error_category &cgdata_category();
+LLVM_ABI const std::error_category &cgdata_category();
 
 enum class cgdata_error {
   success = 0,
@@ -63,7 +64,7 @@ inline std::error_code make_error_code(cgdata_error E) {
   return std::error_code(static_cast<int>(E), cgdata_category());
 }
 
-class CGDataError : public ErrorInfo<CGDataError> {
+class LLVM_ABI CGDataError : public ErrorInfo<CGDataError> {
 public:
   CGDataError(cgdata_error Err, const Twine &ErrStr = Twine())
       : Err(Err), Msg(ErrStr.str()) {
@@ -130,7 +131,7 @@ class CodeGenData {
 public:
   ~CodeGenData() = default;
 
-  static CodeGenData &getInstance();
+  LLVM_ABI static CodeGenData &getInstance();
 
   /// Returns true if we have a valid outlined hash tree.
   bool hasOutlinedHashTree() {
@@ -245,8 +246,8 @@ struct StreamCacheData {
 /// \p Task represents the partition number in the parallel code generation
 /// process. \p AddStream is the callback used to add the serialized module to
 /// the stream.
-void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
-                            AddStreamFn AddStream);
+LLVM_ABI void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
+                                     AddStreamFn AddStream);
 
 /// Load the optimized bitcode module for the second codegen round.
 /// \p OrigModule is the original bitcode module.
@@ -254,18 +255,18 @@ void saveModuleForTwoRounds(const Module &TheModule, unsigned Task,
 /// process. \p Context provides the environment settings for module operations.
 /// \p IRFiles contains optimized bitcode module files needed for loading.
 /// \return A unique_ptr to the loaded Module, or nullptr if loading fails.
-std::unique_ptr<Module> loadModuleForTwoRounds(BitcodeModule &OrigModule,
-                                               unsigned Task,
-                                               LLVMContext &Context,
-                                               ArrayRef<StringRef> IRFiles);
+LLVM_ABI std::unique_ptr<Module>
+loadModuleForTwoRounds(BitcodeModule &OrigModule, unsigned Task,
+                       LLVMContext &Context, ArrayRef<StringRef> IRFiles);
 
 /// Merge the codegen data from the scratch objects \p ObjectFiles from the
 /// first codegen round.
 /// \return the combined hash of the merged codegen data.
-Expected<stable_hash> mergeCodeGenData(ArrayRef<StringRef> ObjectFiles);
+LLVM_ABI Expected<stable_hash>
+mergeCodeGenData(ArrayRef<StringRef> ObjectFiles);
 
-void warn(Error E, StringRef Whence = "");
-void warn(Twine Message, StringRef Whence = "", StringRef Hint = "");
+LLVM_ABI void warn(Error E, StringRef Whence = "");
+LLVM_ABI void warn(Twine Message, StringRef Whence = "", StringRef Hint = "");
 
 } // end namespace cgdata
 
@@ -297,7 +298,7 @@ struct Header {
   // the new field is read correctly.
 
   // Reads a header struct from the buffer.
-  static Expected<Header> readFromBuffer(const unsigned char *Curr);
+  LLVM_ABI static Expected<Header> readFromBuffer(const unsigned char *Curr);
 };
 
 } // end namespace IndexedCGData
diff --git a/llvm/include/llvm/CGData/CodeGenDataReader.h b/llvm/include/llvm/CGData/CodeGenDataReader.h
index 085dd6dd747c9..f915ce0afcd7f 100644
--- a/llvm/include/llvm/CGData/CodeGenDataReader.h
+++ b/llvm/include/llvm/CGData/CodeGenDataReader.h
@@ -16,6 +16,7 @@
 #include "llvm/CGData/CodeGenData.h"
 #include "llvm/CGData/OutlinedHashTreeRecord.h"
 #include "llvm/CGData/StableFunctionMapRecord.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/LineIterator.h"
 #include "llvm/Support/VirtualFileSystem.h"
 
@@ -49,12 +50,12 @@ class CodeGenDataReader {
 
   /// Factory method to create an appropriately typed reader for the given
   /// codegen data file path and file system.
-  static Expected<std::unique_ptr<CodeGenDataReader>>
+  LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>>
   create(const Twine &Path, vfs::FileSystem &FS);
 
   /// Factory method to create an appropriately typed reader for the given
   /// memory buffer.
-  static Expected<std::unique_ptr<CodeGenDataReader>>
+  LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>>
   create(std::unique_ptr<MemoryBuffer> Buffer);
 
   /// Extract the cgdata embedded in sections from the given object file and
@@ -62,7 +63,7 @@ class CodeGenDataReader {
   /// is used by `llvm-cgdata --merge` or ThinLTO's two-codegen rounds.
   /// Optionally, \p CombinedHash can be used to compuate the combined hash of
   /// the merged data.
-  static Error
+  LLVM_ABI static Error
   mergeFromObjectFile(const object::ObjectFile *Obj,
                       OutlinedHashTreeRecord &GlobalOutlineRecord,
                       StableFunctionMapRecord &GlobalFunctionMapRecord,
@@ -98,7 +99,7 @@ class CodeGenDataReader {
   Error success() { return error(cgdata_error::success); }
 };
 
-class IndexedCodeGenDataReader : public CodeGenDataReader {
+class LLVM_ABI IndexedCodeGenDataReader : public CodeGenDataReader {
   /// The codegen data file contents.
   std::unique_ptr<MemoryBuffer> DataBuffer;
   /// The header
@@ -139,7 +140,7 @@ class IndexedCodeGenDataReader : public CodeGenDataReader {
 /// codegen data is recorded. `#` is used to indicate a comment.
 /// The subsequent data is a YAML format per each codegen data in order.
 /// Currently, it only has a function outlined hash tree.
-class TextCodeGenDataReader : public CodeGenDataReader {
+class LLVM_ABI TextCodeGenDataReader : public CodeGenDataReader {
   /// The codegen data file contents.
   std::unique_ptr<MemoryBuffer> DataBuffer;
   /// Iterator over the profile data.
diff --git a/llvm/include/llvm/CGData/CodeGenDataWriter.h b/llvm/include/llvm/CGData/CodeGenDataWriter.h
index 1c4247608999a..faef6beb30aa6 100644
--- a/llvm/include/llvm/CGData/CodeGenDataWriter.h
+++ b/llvm/include/llvm/CGData/CodeGenDataWriter.h
@@ -16,6 +16,7 @@
 #include "llvm/CGData/CodeGenData.h"
 #include "llvm/CGData/OutlinedHashTreeRecord.h"
 #include "llvm/CGData/StableFunctionMapRecord.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/EndianStream.h"
 #include "llvm/Support/Error.h"
 
@@ -45,7 +46,7 @@ class CGDataOStream {
   // \c patch can only be called when all data is written and flushed.
   // For raw_string_ostream, the patch is done on the target string
   // directly and it won't be reflected in the stream's internal buffer.
-  void patch(ArrayRef<CGDataPatchItem> P);
+  LLVM_ABI void patch(ArrayRef<CGDataPatchItem> P);
 
   // If \c OS is an instance of \c raw_fd_ostream, this field will be
   // true. Otherwise, \c OS will be an raw_string_ostream.
@@ -69,16 +70,16 @@ class CodeGenDataWriter {
   ~CodeGenDataWriter() = default;
 
   /// Add the outlined hash tree record. The input hash tree is released.
-  void addRecord(OutlinedHashTreeRecord &Record);
+  LLVM_ABI void addRecord(OutlinedHashTreeRecord &Record);
 
   /// Add the stable function map record. The input function map is released.
-  void addRecord(StableFunctionMapRecord &Record);
+  LLVM_ABI void addRecord(StableFunctionMapRecord &Record);
 
   /// Write the codegen data to \c OS
-  Error write(raw_fd_ostream &OS);
+  LLVM_ABI Error write(raw_fd_ostream &OS);
 
   /// Write the codegen data in text format to \c OS
-  Error writeText(raw_fd_ostream &OS);
+  LLVM_ABI Error writeText(raw_fd_ostream &OS);
 
   /// Return the attributes of the current CGData.
   CGDataKind getCGDataKind() const { return DataKind; }
diff --git a/llvm/include/llvm/CGData/OutlinedHashTree.h b/llvm/include/llvm/CGData/OutlinedHashTree.h
index 9ab36df863eef..d994b68f33ee4 100644
--- a/llvm/include/llvm/CGData/OutlinedHashTree.h
+++ b/llvm/include/llvm/CGData/OutlinedHashTree.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StableHashing.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include <unordered_map>
@@ -54,9 +55,9 @@ class OutlinedHashTree {
   /// the source and the stable_hash of the sink for an edge. These generic
   /// callbacks can be used to traverse a OutlinedHashTree for the purpose of
   /// print debugging or serializing it.
-  void walkGraph(NodeCallbackFn CallbackNode,
-                 EdgeCallbackFn CallbackEdge = nullptr,
-                 bool SortedWalk = false) const;
+  LLVM_ABI void walkGraph(NodeCallbackFn CallbackNode,
+                          EdgeCallbackFn CallbackEdge = nullptr,
+                          bool SortedWalk = false) const;
 
   /// Release all hash nodes except the root hash node.
   void clear() {
@@ -71,10 +72,10 @@ class OutlinedHashTree {
   /// \p GetTerminalCountOnly is true, it only counts the terminal nodes
   /// (meaning it returns the the number of hash sequences in the
   /// OutlinedHashTree).
-  size_t size(bool GetTerminalCountOnly = false) const;
+  LLVM_ABI size_t size(bool GetTerminalCountOnly = false) const;
 
   /// \returns the depth of a OutlinedHashTree by traversing it.
-  size_t depth() const;
+  LLVM_ABI size_t depth() const;
 
   /// \returns the root hash node of a OutlinedHashTree.
   const HashNode *getRoot() const { return &Root; }
@@ -82,13 +83,13 @@ class OutlinedHashTree {
 
   /// Inserts a \p Sequence into the this tree. The last node in the sequence
   /// will increase Terminals.
-  void insert(const HashSequencePair &SequencePair);
+  LLVM_ABI void insert(const HashSequencePair &SequencePair);
 
   /// Merge a \p OtherTree into this Tree.
-  void merge(const OutlinedHashTree *OtherTree);
+  LLVM_ABI void merge(const OutlinedHashTree *OtherTree);
 
   /// \returns the matching count if \p Sequence exists in the OutlinedHashTree.
-  std::optional<unsigned> find(const HashSequence &Sequence) const;
+  LLVM_ABI std::optional<unsigned> find(const HashSequence &Sequence) const;
 
 private:
   HashNode Root;
diff --git a/llvm/include/llvm/CGData/OutlinedHashTreeRecord.h b/llvm/include/llvm/CGData/OutlinedHashTreeRecord.h
index dd599ff6a7a62..d09218dbda73d 100644
--- a/llvm/include/llvm/CGData/OutlinedHashTreeRecord.h
+++ b/llvm/include/llvm/CGData/OutlinedHashTreeRecord.h
@@ -17,6 +17,7 @@
 #define LLVM_CGDATA_OUTLINEDHASHTREERECORD_H
 
 #include "llvm/CGData/OutlinedHashTree.h"
+#include "llvm/Support/Compiler.h"
 
 namespace llvm {
 
@@ -40,13 +41,13 @@ struct OutlinedHashTreeRecord {
       : HashTree(std::move(HashTree)) {};
 
   /// Serialize the outlined hash tree to a raw_ostream.
-  void serialize(raw_ostream &OS) const;
+  LLVM_ABI void serialize(raw_ostream &OS) const;
   /// Deserialize the outlined hash tree from a raw_ostream.
-  void deserialize(const unsigned char *&Ptr);
+  LLVM_ABI void deserialize(const unsigned char *&Ptr);
   /// Serialize the outlined hash tree to a YAML stream.
-  void serializeYAML(yaml::Output &YOS) const;
+  LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
   /// Deserialize the outlined hash tree from a YAML stream.
-  void deserializeYAML(yaml::Input &YIS);
+  LLVM_ABI void deserializeYAML(yaml::Input &YIS);
 
   /// Merge the other outlined hash tree into this one.
   void merge(const OutlinedHashTreeRecord &Other) {
diff --git a/llvm/include/llvm/CGData/StableFunctionMap.h b/llvm/include/llvm/CGData/StableFunctionMap.h
index a3a85b92c3b30..bcb72e8216973 100644
--- a/llvm/include/llvm/CGData/StableFunctionMap.h
+++ b/llvm/include/llvm/CGData/StableFunctionMap.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/IR/StructuralHash.h"
+#include "llvm/Support/Compiler.h"
 
 namespace llvm {
 
@@ -82,18 +83,18 @@ struct StableFunctionMap {
 
   /// Get an existing ID associated with the given name or create a new ID if it
   /// doesn't exist.
-  unsigned getIdOrCreateForName(StringRef Name);
+  LLVM_ABI unsigned getIdOrCreateForName(StringRef Name);
 
   /// Get the name associated with a given ID
-  std::optional<std::string> getNameForId(unsigned Id) const;
+  LLVM_ABI std::optional<std::string> getNameForId(unsigned Id) const;
 
   /// Insert a `StableFunction` object into the function map. This method
   /// handles the uniquing of string names and create a `StableFunctionEntry`
   /// for insertion.
-  void insert(const StableFunction &Func);
+  LLVM_ABI void insert(const StableFunction &Func);
 
   /// Merge a \p OtherMap into this function map.
-  void merge(const StableFunctionMap &OtherMap);
+  LLVM_ABI void merge(const StableFunctionMap &OtherMap);
 
   /// \returns true if there is no stable function entry.
   bool empty() const { return size() == 0; }
@@ -107,10 +108,10 @@ struct StableFunctionMap {
 
   /// \returns the size of StableFunctionMap.
   /// \p Type is the type of size to return.
-  size_t size(SizeType Type = UniqueHashCount) const;
+  LLVM_ABI size_t size(SizeType Type = UniqueHashCount) const;
 
   /// Finalize the stable function map by trimming content.
-  void finalize(bool SkipTrim = false);
+  LLVM_ABI void finalize(bool SkipTrim = false);
 
 private:
   /// Insert a `StableFunctionEntry` into the function map directly. This
diff --git a/llvm/include/llvm/CGData/StableFunctionMapRecord.h b/llvm/include/llvm/CGData/StableFunctionMapRecord.h
index f9b3ed7c646d6..d4d3ffa06ad25 100644
--- a/llvm/include/llvm/CGData/StableFunctionMapRecord.h
+++ b/llvm/include/llvm/CGData/StableFunctionMapRecord.h
@@ -18,6 +18,7 @@
 
 #include "llvm/CGData/StableFunctionMap.h"
 #include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
@@ -34,19 +35,20 @@ struct StableFunctionMapRecord {
 
   /// A static helper function to serialize the stable function map without
   /// owning the stable function map.
-  static void serialize(raw_ostream &OS, const StableFunctionMap *FunctionMap);
+  LLVM_ABI static void serialize(raw_ostream &OS,
+                                 const StableFunctionMap *FunctionMap);
 
   /// Serialize the stable function map to a raw_ostream.
-  void serialize(raw_ostream &OS) const;
+  LLVM_ABI void serialize(raw_ostream &OS) const;
 
   /// Deserialize the stable function map from a raw_ostream.
-  void deserialize(const unsigned char *&Ptr);
+  LLVM_ABI void deserialize(const unsigned char *&Ptr);
 
   /// Serialize the stable function map to a YAML stream.
-  void serializeYAML(yaml::Output &YOS) const;
+  LLVM_ABI void serializeYAML(yaml::Output &YOS) const;
 
   /// Deserialize the stable function map from a YAML stream.
-  void deserializeYAML(yaml::Input &YIS);
+  LLVM_ABI void deserializeYAML(yaml::Input &YIS);
 
   /// Finalize the stable function map by trimming content.
   void finalize(bool SkipTrim = false) { FunctionMap->finalize(SkipTrim); }
diff --git a/llvm/include/llvm/CodeGen/AccelTable.h b/llvm/include/llvm/CodeGen/AccelTable.h
index f98e994b3f998..34c6fda7dcc17 100644
--- a/llvm/include/llvm/CodeGen/AccelTable.h
+++ b/llvm/include/llvm/CodeGen/AccelTable.h
@@ -21,6 +21,7 @@
 #include "llvm/CodeGen/DIE.h"
 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/DJB.h"
 #include "llvm/Support/Debug.h"
 #include <cstdint>
@@ -174,12 +175,12 @@ class AccelTableBase {
   HashList Hashes;
   BucketList Buckets;
 
-  void computeBucketCount();
+  LLVM_ABI void computeBucketCount();
 
   AccelTableBase(HashFn *Hash) : Hash(Hash) {}
 
 public:
-  void finalize(AsmPrinter *Asm, StringRef Prefix);
+  LLVM_ABI void finalize(AsmPrinter *Asm, StringRef Prefix);
   ArrayRef<HashList> getBuckets() const { return Buckets; }
   uint32_t getBucketCount() const { return BucketCount; }
   uint32_t getUniqueHashCount() const { return UniqueHashCount; }
@@ -293,7 +294,8 @@ class DWARF5AccelTableData : public AccelTableData {
 public:
   static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
 
-  DWARF5AccelTableData(const DIE &Die, const uint32_t UnitID, const bool IsTU);
+  LLVM_ABI DWARF5AccelTableData(const DIE &Die, const uint32_t UnitID,
+                                const bool IsTU);
   DWARF5AccelTableData(const uint64_t DieOffset,
                        const std::optional<uint64_t> DefiningParentOffset,
                        const unsigned DieTag, const unsigned UnitID,
@@ -348,7 +350,8 @@ class DWARF5AccelTableData : public AccelTableData {
 
   /// If `Die` has a non-null parent and the parent is not a declaration,
   /// return its offset.
-  static std::optional<uint64_t> getDefiningParentDieOffset(const DIE &Die);
+  LLVM_ABI static std::optional<uint64_t>
+  getDefiningParentDieOffset(const DIE &Die);
 
 protected:
   std::variant<const DIE *, uint64_t> OffsetVal;
@@ -380,7 +383,7 @@ class DebugNamesAbbrev : public FoldingSetNode {
   /// Get DIE Tag.
   uint32_t getDieTag() const { return DieTag; }
   /// Used to gather unique data for the abbreviation folding set.
-  void Profile(FoldingSetNodeID &ID) const;
+  LLVM_ABI void Profile(FoldingSetNodeID &ID) const;
   /// Returns attributes for an abbreviation.
   const SmallVector<AttributeEncoding, 1> &getAttributes() const {
     return AttrVect;
@@ -409,9 +412,9 @@ class DWARF5AccelTable : public AccelTable<DWARF5AccelTableData> {
   /// Returns type units that were constructed.
   const TUVectorTy &getTypeUnitsSymbols() { return TUSymbolsOrHashes; }
   /// Add a type unit start symbol.
-  void addTypeUnitSymbol(DwarfTypeUnit &U);
+  LLVM_ABI void addTypeUnitSymbol(DwarfTypeUnit &U);
   /// Add a type unit Signature.
-  void addTypeUnitSignature(DwarfTypeUnit &U);
+  LLVM_ABI void addTypeUnitSignature(DwarfTypeUnit &U);
   /// Convert DIE entries to explicit offset.
   /// Needs to be called after DIE offsets are computed.
   void convertDieToOffset() {
@@ -437,9 +440,10 @@ class DWARF5AccelTable : public AccelTable<DWARF5AccelTableData> {
   }
 };
 
-void emitAppleAccelTableImpl(AsmPrinter *Asm, AccelTableBase &Contents,
-                             StringRef Prefix, const MCSymbol *SecBegin,
-                             ArrayRef<AppleAccelTableData::Atom> Atoms);
+LLVM_ABI void
+emitAppleAccelTableImpl(AsmPrinter *Asm, AccelTableBase &Contents,
+                        StringRef Prefix, const MCSymbol *SecBegin,
+                        ArrayRef<AppleAccelTableData::Atom> Atoms);
 
 /// Emit an Apple Accelerator Table consisting of entries in the specified
 /// AccelTable. The DataT template parameter should be derived from
@@ -451,15 +455,16 @@ void emitAppleAccelTable(AsmPrinter *Asm, AccelTable<DataT> &Contents,
   emitAppleAccelTableImpl(Asm, Contents, Prefix, SecBegin, DataT::Atoms);
 }
 
-void emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents,
-                          const DwarfDebug &DD,
-                          ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs);
+LLVM_ABI void
+emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents,
+                     const DwarfDebug &DD,
+                     ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs);
 
 /// Emit a DWARFv5 Accelerator Table consisting of entries in the specified
 /// AccelTable. The \p CUs contains either symbols keeping offsets to the
 /// start of compilation unit, either offsets to the start of compilation
 /// unit themselves.
-void emitDWARF5AccelTable(
+LLVM_ABI void emitDWARF5AccelTable(
     AsmPrinter *Asm, DWARF5Accel...
[truncated]

@andrurogerz andrurogerz force-pushed the llvmdll-lib-CodeGen branch from 81256fc to 34fc1b9 Compare May 27, 2025 15:11
@andrurogerz
Copy link
Contributor Author

@compnerd @vgvassilev another one, thank you!

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm.

@compnerd compnerd merged commit 7e4bdb4 into llvm:main May 28, 2025
11 checks passed
@MatzeB
Copy link
Contributor

MatzeB commented May 28, 2025

Why is this called LLVM_ABI (rather than LLVM_API)?

@MatzeB
Copy link
Contributor

MatzeB commented May 28, 2025

Seems the name LLVM_ABI was already decided in #96630; guess I'm too late to the review.

@andrurogerz
Copy link
Contributor Author

Seems the name LLVM_ABI was already decided in #96630; guess I'm too late to the review.

The origins are even older than that. There is some discussion in this discourse from 2021 if you're interested.

@compnerd
Copy link
Member

Why is this called LLVM_ABI (rather than LLVM_API)?

While it annotates the API, the declaration itself becomes part of the ABI. The annotations are to indicate what is the ABI boundary of the module to which it is applied to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants